﻿using DoubanFM.Model;

namespace DoubanFM.ViewModel
{
    /// <summary>
    /// Music item view model
    /// </summary>
    public class MusicItemViewModel : ViewModelCommon
    {
        public MusicItemViewModel(Music music)
            :base(music.Sid, music.Title, music.SmallPicture, music.LargePicture, music.Artist + " - " + music.Title)
        {
            _artist = music.Artist;
            _albumtitle = music.AlbumTitle;
            _publicTime = music.PublicTime;
            _url = music.Url;
            _like = music.IsLike;
        }

        private string _artist = string.Empty;
        public string Artist
        {
            get { return _artist; }
            set { SetProperty(ref _artist, value); }
        }

        private string _albumtitle = string.Empty;
        public string AlbumTitle
        {
            get { return _albumtitle; }
            set { SetProperty(ref _albumtitle, value); }
        }

        private string _publicTime;
        public string PublicTime
        {
            get { return _publicTime; }
            set { SetProperty(ref _publicTime, value); }
        }

        private string _url = string.Empty;
        public string Url
        {
            get { return _url; }
            set { SetProperty(ref _url, value); }
        }

        private bool _like;
        public bool IsLike
        {
            get { return _like; }
            set { SetProperty(ref _like, value); }
        }

        public override bool Equals(System.Object obj)
        {
            // If parameter is null return false.
            if (obj == null)
            {
                return false;
            }

            // If parameter cannot be cast to Point return false.
            var m = obj as MusicItemViewModel;
            if (m == null)
            {
                return false;
            }

            // Return true if the id match:
            return UniqueId == m.UniqueId;
        }

        public override int GetHashCode()
        {
            return 13 ^ UniqueId.GetHashCode();
        }
    }
}
